﻿      $(document).ready(function () {

          $('.banLink').click(function () {
              /*When the admin clicks on the ban link this script will 
              use ajax and refrech the table whit list of all players except the player the admin just baned.
              */
              var UserName = $(this).attr("id");
              var newData = { "Username": UserName };
            
              if (confirm('Are you sure you want to ban ' + UserName)) {
                  $.ajax({
                      type: "POST",
                      url: "/Admin/banPlayer",
                      data: newData,
                      success: function (data) {

                          $('#sboard').remove();
                          var NewHtml = '<table id="sboard">\
                                      <thead>\
                                      <tr>\
                                      <th>Username</th>\
                                      <th>Points</th>\
                                      <th>Email</th>\
                                      <th>Ban</th>\
                                      </tr>\
                                      </thead>\
                                      <tbody>';
                          for (var i = 0; i < data.length ; i++) {


                              NewHtml += '<tr>\
                                        <td>';
                              NewHtml += '<a href="/admin/Profile/' + data[i].UserId + '">' + data[i].UserName + '</a>';
                              NewHtml += '</td>\
                                       <td>';
                              NewHtml += data[i].OverallScore;
                              NewHtml += '</td>\
                                       <td>';
                              NewHtml += data[i].Email;
                              NewHtml += '</td>\
                                       <td><a href="#" id="';
                              NewHtml += data[i].UserName;
                              NewHtml += '" class="banLink">Ban</a></td>\
                                       </tr>';
                   
                          }
                          NewHtml += '</tbody>\
                                       </table>';
                          $(NewHtml).insertAfter('.heading');
                      }

                  });
              }
              else {
                  // nothing.  


              }
          });

      });
    
